In [1]:
%matplotlib inline
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandoc

Se lee la base de datos sobre el archivo de excel, se guarda en un 'dataframe' (objeto sobre el cual se hacen operaciones)


In [3]:
data_set = pd.read_excel('/home/sergio/Workspace/enc/__BD Prejuicios Luz (5).xlsx', sheetname='BD')

In [4]:
data_set.columns.tolist()


Out[4]:
[u'#',
 u'Folio',
 u'Alumno',
 u'Consentimiento',
 u'Mayor Edad',
 u'Sexo',
 u'Edad',
 u'Lugar_Origen',
 u'Estado_civil',
 u'Escolaridad',
 u'Orientacion_Religiosa',
 u'Practicante',
 u'Orientacion_Sexual',
 u'Pareja',
 u'Tiempo',
 u'Emocion1',
 u'Emocion2',
 u'Emocion3',
 u'Emocion4',
 u'Emocion5',
 u'Emocion6',
 u'Emocion7',
 u'Emocion8',
 u'Emocion9',
 u'Emocion10',
 u'Emocion11',
 u'Emocion12',
 u'Emocion13',
 u'Emocion14',
 u'Emocion15',
 u'Emocion16',
 u'Emocion17',
 u'Emocion18',
 u'Emocion19',
 u'Emocion20',
 u'Emocion21',
 u'Emocion22',
 u'Emocion23',
 u'Emocion24',
 u'Emocion25',
 u'Emocion26',
 u'Emocion27',
 u'Emocion28',
 u'Emocion29',
 u'Emocion30',
 u'Emocion31',
 u'Emocion32',
 u'Emocion33',
 u'Emocion34',
 u'Emocion35',
 u'Emocion36',
 u'Emocion37',
 u'Emocion38',
 u'Emocion39',
 u'Emocion40',
 u'Emocion41',
 u'Emocion42',
 u'Emocion43',
 u'Emocion44',
 u'Emocion45',
 u'Emocion46',
 u'Cognicion1',
 u'Cognicion2',
 u'Cognicion3',
 u'Cognicion4',
 u'Cognicion5',
 u'Cognicion6',
 u'Cognicion7',
 u'Cognicion8',
 u'Cognicion9',
 u'Cognicion10',
 u'Cognicion11',
 u'Cognicion12',
 u'Cognicion13',
 u'Cognicion14',
 u'Cognicion15',
 u'Cognicion16',
 u'Cognicion17',
 u'Cognicion18',
 u'Cognicion19',
 u'Cognicion20',
 u'Cognicion21',
 u'Cognicion22',
 u'Cognicion23',
 u'Cognicion24',
 u'Cognicion25',
 u'Cognicion26',
 u'Cognicion27',
 u'Cognicion28',
 u'Cognicion29',
 u'Cognicion30',
 u'Cognicion31',
 u'Cognicion32',
 u'Cognicion33',
 u'Cognicion34',
 u'Cognicion35',
 u'Cognicion36',
 u'Cognicion37',
 u'Cognicion38',
 u'Cognicion39',
 u'Cognicion40',
 u'Cognicion41',
 u'Cognicion42',
 u'Cognicion43',
 u'Cognicion44',
 u'Cognicion45',
 u'Cognicion46',
 u'Cognicion47',
 u'Cognicion48',
 u'Cognicion49',
 u'Cognicion50',
 u'Cognicion51',
 u'Cognicion52',
 u'Cognicion53',
 u'Cognicion54',
 u'Cognicion55',
 u'Cognicion56',
 u'Cognicion57',
 u'Cognicion58',
 u'Cognicion59',
 u'Cognicion60',
 u'Cognicion61',
 u'Cognicion62',
 u'Cognicion63',
 u'Cognicion64',
 u'Cognicion65',
 u'Cognicion66',
 u'Cognicion67',
 u'Cognicion68',
 u'Cognicion69',
 u'Cognicion70',
 u'Cognicion71',
 u'Cognicion72',
 u'Cognicion73',
 u'Cognicion74',
 u'Cognicion75',
 u'Cognicion76',
 u'Cognicion77',
 u'Cognicion78',
 u'Cognicion79',
 u'Conducta1',
 u'Conducta2',
 u'Conducta3',
 u'Conducta4',
 u'Conducta5',
 u'Conducta6',
 u'Conducta7',
 u'Conducta8',
 u'Conducta9',
 u'Conducta10',
 u'Conducta11',
 u'Conducta12',
 u'Conducta13',
 u'Conducta14',
 u'Conducta15',
 u'Conducta16',
 u'Conducta17',
 u'Conducta18',
 u'Conducta19',
 u'Conducta20',
 u'Conducta21',
 u'Conducta22',
 u'Conducta23',
 u'Conducta24',
 u'Conducta25',
 u'Conducta26',
 u'Conducta27',
 u'Conducta28',
 u'Conducta29',
 u'Conducta30',
 u'Conducta31',
 u'Conducta32',
 u'Conducta33',
 u'Conducta34',
 u'Conducta35',
 u'Conducta36',
 u'Conducta37',
 u'Conducta38',
 u'Conducta39',
 u'Conducta40',
 u'Conducta41',
 u'Conducta42',
 u'Conducta43',
 u'Conducta44',
 u'Conducta45',
 u'Conducta46',
 u'Conducta47',
 u'Conducta48',
 u'Conducta49',
 u'Conducta50',
 u'Conducta51',
 u'Conducta52',
 u'Conducta53',
 u'Conducta54',
 u'Conducta55',
 u'Conducta56',
 u'Creencia1',
 u'Creencia2',
 u'Creencia3',
 u'Creencia4',
 u'Creencia5',
 u'Creencia6',
 u'Creencia7',
 u'Creencia8',
 u'Creencia9',
 u'Creencia10',
 u'Creencia11',
 u'Creencia12',
 u'Creencia13',
 u'Creencia14',
 u'Creencia15',
 u'Creencia16',
 u'Creencia17',
 u'Creencia18',
 u'Creencia19',
 u'Creencia20',
 u'Creencia21',
 u'Creencia22',
 u'Creencia23',
 u'Creencia24',
 u'Creencia25',
 u'Creencia26',
 u'Creencia27',
 u'Creencia28',
 u'Creencia29',
 u'Creencia30',
 u'Creencia31',
 u'Creencia32',
 u'Creencia33',
 u'Creencia34',
 u'Creencia35',
 u'Creencia36',
 u'Creencia37',
 u'Creencia38',
 u'Creencia39',
 u'Creencia40',
 u'Creencia41',
 u'Creencia42',
 u'Creencia43',
 u'Creencia44',
 u'Creencia45',
 u'Creencia46',
 u'Creencia47',
 u'Creencia48',
 u'Creencia49',
 u'Creencia50',
 u'Creencia51']

In [5]:
data_set.to_pickle('/home/sergio/Workspace/enc/full_data_enc.pkl')

In [6]:
data = pd.read_pickle('/home/sergio/Workspace/enc/full_data_enc.pkl')

In [7]:
data.columns.tolist()


Out[7]:
[u'#',
 u'Folio',
 u'Alumno',
 u'Consentimiento',
 u'Mayor Edad',
 u'Sexo',
 u'Edad',
 u'Lugar_Origen',
 u'Estado_civil',
 u'Escolaridad',
 u'Orientacion_Religiosa',
 u'Practicante',
 u'Orientacion_Sexual',
 u'Pareja',
 u'Tiempo',
 u'Emocion1',
 u'Emocion2',
 u'Emocion3',
 u'Emocion4',
 u'Emocion5',
 u'Emocion6',
 u'Emocion7',
 u'Emocion8',
 u'Emocion9',
 u'Emocion10',
 u'Emocion11',
 u'Emocion12',
 u'Emocion13',
 u'Emocion14',
 u'Emocion15',
 u'Emocion16',
 u'Emocion17',
 u'Emocion18',
 u'Emocion19',
 u'Emocion20',
 u'Emocion21',
 u'Emocion22',
 u'Emocion23',
 u'Emocion24',
 u'Emocion25',
 u'Emocion26',
 u'Emocion27',
 u'Emocion28',
 u'Emocion29',
 u'Emocion30',
 u'Emocion31',
 u'Emocion32',
 u'Emocion33',
 u'Emocion34',
 u'Emocion35',
 u'Emocion36',
 u'Emocion37',
 u'Emocion38',
 u'Emocion39',
 u'Emocion40',
 u'Emocion41',
 u'Emocion42',
 u'Emocion43',
 u'Emocion44',
 u'Emocion45',
 u'Emocion46',
 u'Cognicion1',
 u'Cognicion2',
 u'Cognicion3',
 u'Cognicion4',
 u'Cognicion5',
 u'Cognicion6',
 u'Cognicion7',
 u'Cognicion8',
 u'Cognicion9',
 u'Cognicion10',
 u'Cognicion11',
 u'Cognicion12',
 u'Cognicion13',
 u'Cognicion14',
 u'Cognicion15',
 u'Cognicion16',
 u'Cognicion17',
 u'Cognicion18',
 u'Cognicion19',
 u'Cognicion20',
 u'Cognicion21',
 u'Cognicion22',
 u'Cognicion23',
 u'Cognicion24',
 u'Cognicion25',
 u'Cognicion26',
 u'Cognicion27',
 u'Cognicion28',
 u'Cognicion29',
 u'Cognicion30',
 u'Cognicion31',
 u'Cognicion32',
 u'Cognicion33',
 u'Cognicion34',
 u'Cognicion35',
 u'Cognicion36',
 u'Cognicion37',
 u'Cognicion38',
 u'Cognicion39',
 u'Cognicion40',
 u'Cognicion41',
 u'Cognicion42',
 u'Cognicion43',
 u'Cognicion44',
 u'Cognicion45',
 u'Cognicion46',
 u'Cognicion47',
 u'Cognicion48',
 u'Cognicion49',
 u'Cognicion50',
 u'Cognicion51',
 u'Cognicion52',
 u'Cognicion53',
 u'Cognicion54',
 u'Cognicion55',
 u'Cognicion56',
 u'Cognicion57',
 u'Cognicion58',
 u'Cognicion59',
 u'Cognicion60',
 u'Cognicion61',
 u'Cognicion62',
 u'Cognicion63',
 u'Cognicion64',
 u'Cognicion65',
 u'Cognicion66',
 u'Cognicion67',
 u'Cognicion68',
 u'Cognicion69',
 u'Cognicion70',
 u'Cognicion71',
 u'Cognicion72',
 u'Cognicion73',
 u'Cognicion74',
 u'Cognicion75',
 u'Cognicion76',
 u'Cognicion77',
 u'Cognicion78',
 u'Cognicion79',
 u'Conducta1',
 u'Conducta2',
 u'Conducta3',
 u'Conducta4',
 u'Conducta5',
 u'Conducta6',
 u'Conducta7',
 u'Conducta8',
 u'Conducta9',
 u'Conducta10',
 u'Conducta11',
 u'Conducta12',
 u'Conducta13',
 u'Conducta14',
 u'Conducta15',
 u'Conducta16',
 u'Conducta17',
 u'Conducta18',
 u'Conducta19',
 u'Conducta20',
 u'Conducta21',
 u'Conducta22',
 u'Conducta23',
 u'Conducta24',
 u'Conducta25',
 u'Conducta26',
 u'Conducta27',
 u'Conducta28',
 u'Conducta29',
 u'Conducta30',
 u'Conducta31',
 u'Conducta32',
 u'Conducta33',
 u'Conducta34',
 u'Conducta35',
 u'Conducta36',
 u'Conducta37',
 u'Conducta38',
 u'Conducta39',
 u'Conducta40',
 u'Conducta41',
 u'Conducta42',
 u'Conducta43',
 u'Conducta44',
 u'Conducta45',
 u'Conducta46',
 u'Conducta47',
 u'Conducta48',
 u'Conducta49',
 u'Conducta50',
 u'Conducta51',
 u'Conducta52',
 u'Conducta53',
 u'Conducta54',
 u'Conducta55',
 u'Conducta56',
 u'Creencia1',
 u'Creencia2',
 u'Creencia3',
 u'Creencia4',
 u'Creencia5',
 u'Creencia6',
 u'Creencia7',
 u'Creencia8',
 u'Creencia9',
 u'Creencia10',
 u'Creencia11',
 u'Creencia12',
 u'Creencia13',
 u'Creencia14',
 u'Creencia15',
 u'Creencia16',
 u'Creencia17',
 u'Creencia18',
 u'Creencia19',
 u'Creencia20',
 u'Creencia21',
 u'Creencia22',
 u'Creencia23',
 u'Creencia24',
 u'Creencia25',
 u'Creencia26',
 u'Creencia27',
 u'Creencia28',
 u'Creencia29',
 u'Creencia30',
 u'Creencia31',
 u'Creencia32',
 u'Creencia33',
 u'Creencia34',
 u'Creencia35',
 u'Creencia36',
 u'Creencia37',
 u'Creencia38',
 u'Creencia39',
 u'Creencia40',
 u'Creencia41',
 u'Creencia42',
 u'Creencia43',
 u'Creencia44',
 u'Creencia45',
 u'Creencia46',
 u'Creencia47',
 u'Creencia48',
 u'Creencia49',
 u'Creencia50',
 u'Creencia51']

Se seleccionan las columnas que nos sirven para contestar la pregunta: ¿Qué grupo de edad sufre de más prejucios sexuales ? Adultos mayores o Jóvenes


In [8]:
data_useful = data[['Sexo', 'Edad', 'Lugar_Origen', 'Estado_civil',
                   'Escolaridad', 'Orientacion_Religiosa', 'Practicante', 'Orientacion_Sexual',
                   'Pareja', 'Emocion1', 'Emocion2', 'Emocion3', 'Emocion4', 'Emocion8', 'Emocion9',
                   'Emocion14', 'Emocion15', 'Emocion17', 'Emocion21', 'Emocion26', 'Emocion28',
                   'Emocion34', 'Emocion36', 'Cognicion6', 'Cognicion7', 'Cognicion9', 'Cognicion10',
                   'Cognicion11', 'Cognicion15', 'Cognicion21', 'Cognicion30', 'Cognicion41', 'Cognicion47',
                   'Cognicion50', 'Cognicion54', 'Cognicion58', 'Cognicion65', 'Cognicion74', 'Cognicion75',
                   'Cognicion78', 'Conducta1', 'Conducta2', 'Conducta6', 'Conducta13', 'Conducta19', 'Conducta21',
                   'Conducta23', 'Conducta25', 'Conducta31', 'Conducta32', 'Conducta36', 'Conducta41', 'Conducta46',
                   'Conducta52', 'Creencia2', 'Creencia12', 'Creencia27', 'Creencia37', 'Creencia39', 'Creencia49']]

In [9]:
data_useful.columns.tolist()


Out[9]:
[u'Sexo',
 u'Edad',
 u'Lugar_Origen',
 u'Estado_civil',
 u'Escolaridad',
 u'Orientacion_Religiosa',
 u'Practicante',
 u'Orientacion_Sexual',
 u'Pareja',
 u'Emocion1',
 u'Emocion2',
 u'Emocion3',
 u'Emocion4',
 u'Emocion8',
 u'Emocion9',
 u'Emocion14',
 u'Emocion15',
 u'Emocion17',
 u'Emocion21',
 u'Emocion26',
 u'Emocion28',
 u'Emocion34',
 u'Emocion36',
 u'Cognicion6',
 u'Cognicion7',
 u'Cognicion9',
 u'Cognicion10',
 u'Cognicion11',
 u'Cognicion15',
 u'Cognicion21',
 u'Cognicion30',
 u'Cognicion41',
 u'Cognicion47',
 u'Cognicion50',
 u'Cognicion54',
 u'Cognicion58',
 u'Cognicion65',
 u'Cognicion74',
 u'Cognicion75',
 u'Cognicion78',
 u'Conducta1',
 u'Conducta2',
 u'Conducta6',
 u'Conducta13',
 u'Conducta19',
 u'Conducta21',
 u'Conducta23',
 u'Conducta25',
 u'Conducta31',
 u'Conducta32',
 u'Conducta36',
 u'Conducta41',
 u'Conducta46',
 u'Conducta52',
 u'Creencia2',
 u'Creencia12',
 u'Creencia27',
 u'Creencia37',
 u'Creencia39',
 u'Creencia49']

In [ ]:
data_useful.to_pickle('/home/sergio/Workspace/enc/data_usefull_enc.pkl')

In [3]:
data_useful = pd.read_pickle('/home/sergio/Workspace/enc/data_usefull_enc.pkl')

Se guardan los datos en un archivo para poder ser reconstruidos facilmente


In [10]:
data_useful


Out[10]:
Sexo Edad Lugar_Origen Estado_civil Escolaridad Orientacion_Religiosa Practicante Orientacion_Sexual Pareja Emocion1 ... Conducta36 Conducta41 Conducta46 Conducta52 Creencia2 Creencia12 Creencia27 Creencia37 Creencia39 Creencia49
0 2 50 9 2 3 1 2 1 1 5 ... 2 2 5 3 1 2 1 1 1 1
1 1 50 9 2 3 1 2 1 1 5 ... 3 3 2 5 1 2 1 1 1 2
2 2 19 9 1 4 2 3 1 0 4 ... 4 3 4 5 1 1 1 1 1 1
3 2 22 9 1 4 8 3 2 2 4 ... 2 3 4 1 2 1 1 1 1 1
4 2 22 9 1 4 8 1 1 2 4 ... 2 3 4 1 2 1 1 1 1 1
5 1 20 9 1 3 1 1 1 2 3 ... 4 4 3 3 2 1 2 1 1 2
6 1 20 9 1 3 1 3 1 2 5 ... 4 3 2 4 1 2 1 1 1 2
7 1 20 9 1 4 1 4 1 2 4 ... 2 4 2 3 1 1 1 1 1 1
8 1 20 9 1 4 8 4 1 2 4 ... 3 2 1 4 1 1 1 1 1 1
9 1 18 9 1 4 2 2 1 2 4 ... 4 3 4 5 2 1 1 1 1 1
10 1 20 9 1 4 1 3 1 2 4 ... 3 3 3 5 1 1 1 1 1 1
11 2 19 9 1 4 1 2 1 1 5 ... 1 1 3 4 2 2 1 1 1 1
12 2 51 9 1 3 1 1 1 1 5 ... 4 2 1 4 1 1 1 1 1 1
13 2 20 9 1 4 1 1 3 1 4 ... 2 2 3 4 1 1 1 1 1 1
14 2 43 9 2 3 1 4 1 1 4 ... 5 3 4 4 1 2 1 1 2 1
15 2 18 9 1 4 1 2 1 2 3 ... 4 3 1 3 1 1 1 1 1 1
16 2 20 9 1 4 8 3 1 2 2 ... 3 1 3 3 1 1 1 1 1 1
17 2 23 9 1 4 9 1 1 2 4 ... 2 4 2 3 1 1 1 1 1 1
18 2 23 9 1 4 7 3 1 1 3 ... 2 2 1 4 1 1 1 1 1 1
19 2 27 9 1 4 1 1 1 2 3 ... 2 2 2 4 1 1 1 1 1 1
20 2 23 9 1 4 8 4 1 1 3 ... 3 3 3 2 1 1 1 1 1 1
21 1 22 1 1 4 1 4 1 2 4 ... 2 3 3 3 1 1 1 1 1 1
22 1 21 9 1 4 1 3 2 1 4 ... 5 2 1 5 1 1 1 1 1 1
23 2 55 9 4 4 1 2 1 2 4 ... 2 1 4 4 1 1 1 1 1 1
24 2 29 9 1 4 1 1 1 2 3 ... 3 3 2 3 1 1 1 1 1 1
25 2 79 9 5 5 1 3 1 2 4 ... 1 3 1 2 1 2 1 2 1 1
26 2 23 9 1 3 1 4 1 2 4 ... 4 5 5 5 1 2 1 1 2 1
27 2 32 9 2 3 1 3 1 1 4 ... 3 1 1 4 1 1 1 1 1 1
28 2 23 9 1 3 1 4 1 2 4 ... 3 1 4 3 1 1 1 1 1 1
29 1 45 9 2 4 1 3 1 1 4 ... 4 2 2 3 1 1 1 1 1 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
469 1 18 9 1 3 8 1 1 1 4 ... 3 3 1 3 1 1 1 1 1 1
470 1 22 9 1 4 8 1 1 2 4 ... 4 4 3 3 1 1 1 1 1 1
471 1 56 9 2 5 1 1 1 1 5 ... 2 5 2 5 1 2 1 1 1 1
472 1 45 9 4 4 1 4 1 2 5 ... 1 4 2 4 1 1 1 1 1 1
473 1 23 9 1 4 2 4 2 1 2 ... 1 2 2 3 2 1 1 1 1 1
474 2 22 9 1 4 2 3 2 2 4 ... 2 2 4 3 1 1 1 1 1 1
475 2 21 9 1 4 1 3 1 2 2 ... 3 3 1 2 2 1 1 1 1 1
476 2 18 9 1 3 8 1 2 1 3 ... 4 3 3 3 2 1 1 1 1 1
477 2 45 9 2 4 1 3 1 1 3 ... 1 4 1 5 1 1 1 1 1 1
478 2 44 9 2 4 1 3 1 1 2 ... 2 2 3 2 1 1 1 1 1 1
479 2 19 9 1 3 8 1 1 2 1 ... 3 3 4 3 1 1 1 1 1 1
480 2 22 9 1 4 8 1 3 2 4 ... 2 4 3 4 1 1 1 1 1 1
481 2 21 9 1 4 7 1 1 1 2 ... 4 5 3 2 2 1 1 1 1 1
482 2 26 9 1 4 8 1 1 2 2 ... 4 4 3 3 1 1 1 1 1 1
483 2 28 9 2 4 1 3 1 1 4 ... 1 5 2 4 1 1 1 1 1 1
484 2 30 9 2 4 1 2 1 1 3 ... 1 3 2 3 1 1 1 1 1 1
485 2 32 9 3 4 1 2 1 1 4 ... 2 3 2 2 1 1 1 1 1 1
486 2 35 9 3 4 8 1 1 1 4 ... 3 3 1 3 1 1 1 1 1 1
487 2 37 9 2 4 7 1 1 1 2 ... 3 4 1 3 1 1 1 1 1 1
488 2 18 9 1 3 8 1 2 2 3 ... 4 3 1 3 1 1 1 1 1 1
489 1 21 9 1 4 1 2 1 2 5 ... 1 3 4 4 1 1 1 1 1 1
490 1 35 14 2 4 1 2 1 1 5 ... 2 3 3 2 2 1 1 1 1 1
491 2 27 15 4 4 8 1 1 2 3 ... 1 5 1 3 2 2 1 1 2 2
492 2 22 15 1 3 8 1 2 2 4 ... 5 2 2 4 1 1 1 1 1 1
493 1 21 9 2 3 8 1 1 1 5 ... 2 3 1 2 1 2 1 1 1 1
494 2 24 9 3 4 1 3 1 1 4 ... 3 3 2 3 1 1 1 1 1 1
495 2 25 17 1 4 2 4 1 2 4 ... 2 2 2 4 1 1 1 1 1 1
496 2 23 12 2 3 3 3 2 1 3 ... 2 3 3 3 1 1 1 1 1 1
497 1 27 9 1 4 1 2 1 2 5 ... 3 5 1 5 2 1 2 2 1 1
498 1 33 9 1 4 9 3 1 2 1 ... 2 4 1 4 1 1 1 1 1 1

499 rows × 60 columns


In [4]:
data_useful.Cognicion58.unique()


Out[4]:
array([  3.,   5.,   2.,   1.,   4.,  33.,  nan])

Se observa que algunas preguntas no tienen respuestas validas, esto puede ser por error humano de transcripcion de datos.


In [11]:
plot_1 = sns.distplot(data_useful.Edad.dropna(), bins=10)
plot_1.set(xlabel='Edad', ylabel='Kernel Density')
plt.show()



In [12]:
data_useful.Edad.plot(kind='hist', bins=10, title='Histograma edad')
plt.show


Out[12]:
<function matplotlib.pyplot.show>

In [13]:
data_useful.Orientacion_Religiosa.plot(kind='hist', title='Histograma Religion', color='m')


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fae2441a350>

In [14]:
data_useful.Escolaridad.plot(kind='hist', bins=23, title='Escolaridad', color='r')


Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fae222fcb90>

In [15]:
data_useful.Sexo.plot(kind='hist', bins=3, title='Sexo', color='b')


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fae2229e690>

In [16]:
columnas = ['Emocion1', 'Emocion2', 'Emocion3', 'Emocion4', 'Emocion8', 'Emocion9',
                   'Emocion14', 'Emocion15', 'Emocion17', 'Emocion21', 'Emocion26', 'Emocion28',
                   'Emocion34', 'Emocion36', 'Cognicion6', 'Cognicion7', 'Cognicion9', 'Cognicion10',
                   'Cognicion11', 'Cognicion15', 'Cognicion21', 'Cognicion30', 'Cognicion41', 'Cognicion47',
                   'Cognicion50', 'Cognicion54', 'Cognicion58', 'Cognicion65', 'Cognicion74', 'Cognicion75',
                   'Cognicion78', 'Conducta1', 'Conducta2', 'Conducta6', 'Conducta13', 'Conducta19', 'Conducta21',
                   'Conducta23', 'Conducta25', 'Conducta31', 'Conducta32', 'Conducta36', 'Conducta41', 'Conducta46',
                   'Conducta52', 'Creencia2', 'Creencia12', 'Creencia27', 'Creencia37', 'Creencia39', 'Creencia49']

In [17]:
data_clean = data_useful[data_useful[columnas].isin([1,2,3,4,5])]

In [18]:
data_clean[['Sexo', 'Edad', 'Lugar_Origen', 'Estado_civil',
                   'Escolaridad', 'Orientacion_Religiosa', 'Practicante', 'Orientacion_Sexual',
                   'Pareja']] = data_useful[['Sexo', 'Edad', 'Lugar_Origen', 'Estado_civil',
                   'Escolaridad', 'Orientacion_Religiosa', 'Practicante', 'Orientacion_Sexual',
                   'Pareja']]

In [19]:
data_clean.head()


Out[19]:
Sexo Edad Lugar_Origen Estado_civil Escolaridad Orientacion_Religiosa Practicante Orientacion_Sexual Pareja Emocion1 ... Conducta36 Conducta41 Conducta46 Conducta52 Creencia2 Creencia12 Creencia27 Creencia37 Creencia39 Creencia49
0 2 50 9 2 3 1 2 1 1 5 ... 2 2 5 3 1 2 1 1 1 1
1 1 50 9 2 3 1 2 1 1 5 ... 3 3 2 5 1 2 1 1 1 2
2 2 19 9 1 4 2 3 1 0 4 ... 4 3 4 5 1 1 1 1 1 1
3 2 22 9 1 4 8 3 2 2 4 ... 2 3 4 1 2 1 1 1 1 1
4 2 22 9 1 4 8 1 1 2 4 ... 2 3 4 1 2 1 1 1 1 1

5 rows × 60 columns


In [20]:
data_useful.head()


Out[20]:
Sexo Edad Lugar_Origen Estado_civil Escolaridad Orientacion_Religiosa Practicante Orientacion_Sexual Pareja Emocion1 ... Conducta36 Conducta41 Conducta46 Conducta52 Creencia2 Creencia12 Creencia27 Creencia37 Creencia39 Creencia49
0 2 50 9 2 3 1 2 1 1 5 ... 2 2 5 3 1 2 1 1 1 1
1 1 50 9 2 3 1 2 1 1 5 ... 3 3 2 5 1 2 1 1 1 2
2 2 19 9 1 4 2 3 1 0 4 ... 4 3 4 5 1 1 1 1 1 1
3 2 22 9 1 4 8 3 2 2 4 ... 2 3 4 1 2 1 1 1 1 1
4 2 22 9 1 4 8 1 1 2 4 ... 2 3 4 1 2 1 1 1 1 1

5 rows × 60 columns


In [21]:
n_data = data_clean.dropna(subset=[columnas]).copy()
n_data[['Emocion1', 'Emocion2', 'Emocion3', 'Emocion4', 'Emocion8', 'Emocion9',
                   'Emocion14', 'Emocion15', 'Emocion17', 'Emocion21', 'Emocion26', 'Emocion28',
                   'Emocion34', 'Emocion36', 'Cognicion6', 'Cognicion7', 'Cognicion9', 'Cognicion10',
                   'Cognicion11', 'Cognicion15', 'Cognicion21', 'Cognicion30', 'Cognicion41', 'Cognicion47',
                   'Cognicion50', 'Cognicion54', 'Cognicion58', 'Cognicion65', 'Cognicion74', 'Cognicion75',
                   'Cognicion78', 'Conducta1', 'Conducta2', 'Conducta6', 'Conducta13', 'Conducta19', 'Conducta21',
                   'Conducta23', 'Conducta25', 'Conducta31', 'Conducta32', 'Conducta36', 'Conducta41', 'Conducta46',
                   'Conducta52']] = MinMaxScaler().fit_transform(n_data[['Emocion1', 'Emocion2', 'Emocion3', 'Emocion4', 'Emocion8', 'Emocion9',
                   'Emocion14', 'Emocion15', 'Emocion17', 'Emocion21', 'Emocion26', 'Emocion28',
                   'Emocion34', 'Emocion36', 'Cognicion6', 'Cognicion7', 'Cognicion9', 'Cognicion10',
                   'Cognicion11', 'Cognicion15', 'Cognicion21', 'Cognicion30', 'Cognicion41', 'Cognicion47',
                   'Cognicion50', 'Cognicion54', 'Cognicion58', 'Cognicion65', 'Cognicion74', 'Cognicion75',
                   'Cognicion78', 'Conducta1', 'Conducta2', 'Conducta6', 'Conducta13', 'Conducta19', 'Conducta21',
                   'Conducta23', 'Conducta25', 'Conducta31', 'Conducta32', 'Conducta36', 'Conducta41', 'Conducta46',
                   'Conducta52']])

In [22]:
len(n_data)


Out[22]:
490

In [23]:
n_data


Out[23]:
Sexo Edad Lugar_Origen Estado_civil Escolaridad Orientacion_Religiosa Practicante Orientacion_Sexual Pareja Emocion1 ... Conducta36 Conducta41 Conducta46 Conducta52 Creencia2 Creencia12 Creencia27 Creencia37 Creencia39 Creencia49
0 2 50 9 2 3 1 2 1 1 1.00 ... 0.25 0.25 1.00 0.50 1 2 1 1 1 1
1 1 50 9 2 3 1 2 1 1 1.00 ... 0.50 0.50 0.25 1.00 1 2 1 1 1 2
2 2 19 9 1 4 2 3 1 0 0.75 ... 0.75 0.50 0.75 1.00 1 1 1 1 1 1
3 2 22 9 1 4 8 3 2 2 0.75 ... 0.25 0.50 0.75 0.00 2 1 1 1 1 1
4 2 22 9 1 4 8 1 1 2 0.75 ... 0.25 0.50 0.75 0.00 2 1 1 1 1 1
5 1 20 9 1 3 1 1 1 2 0.50 ... 0.75 0.75 0.50 0.50 2 1 2 1 1 2
6 1 20 9 1 3 1 3 1 2 1.00 ... 0.75 0.50 0.25 0.75 1 2 1 1 1 2
7 1 20 9 1 4 1 4 1 2 0.75 ... 0.25 0.75 0.25 0.50 1 1 1 1 1 1
8 1 20 9 1 4 8 4 1 2 0.75 ... 0.50 0.25 0.00 0.75 1 1 1 1 1 1
9 1 18 9 1 4 2 2 1 2 0.75 ... 0.75 0.50 0.75 1.00 2 1 1 1 1 1
10 1 20 9 1 4 1 3 1 2 0.75 ... 0.50 0.50 0.50 1.00 1 1 1 1 1 1
11 2 19 9 1 4 1 2 1 1 1.00 ... 0.00 0.00 0.50 0.75 2 2 1 1 1 1
12 2 51 9 1 3 1 1 1 1 1.00 ... 0.75 0.25 0.00 0.75 1 1 1 1 1 1
13 2 20 9 1 4 1 1 3 1 0.75 ... 0.25 0.25 0.50 0.75 1 1 1 1 1 1
14 2 43 9 2 3 1 4 1 1 0.75 ... 1.00 0.50 0.75 0.75 1 2 1 1 2 1
15 2 18 9 1 4 1 2 1 2 0.50 ... 0.75 0.50 0.00 0.50 1 1 1 1 1 1
16 2 20 9 1 4 8 3 1 2 0.25 ... 0.50 0.00 0.50 0.50 1 1 1 1 1 1
17 2 23 9 1 4 9 1 1 2 0.75 ... 0.25 0.75 0.25 0.50 1 1 1 1 1 1
18 2 23 9 1 4 7 3 1 1 0.50 ... 0.25 0.25 0.00 0.75 1 1 1 1 1 1
19 2 27 9 1 4 1 1 1 2 0.50 ... 0.25 0.25 0.25 0.75 1 1 1 1 1 1
20 2 23 9 1 4 8 4 1 1 0.50 ... 0.50 0.50 0.50 0.25 1 1 1 1 1 1
21 1 22 1 1 4 1 4 1 2 0.75 ... 0.25 0.50 0.50 0.50 1 1 1 1 1 1
22 1 21 9 1 4 1 3 2 1 0.75 ... 1.00 0.25 0.00 1.00 1 1 1 1 1 1
23 2 55 9 4 4 1 2 1 2 0.75 ... 0.25 0.00 0.75 0.75 1 1 1 1 1 1
24 2 29 9 1 4 1 1 1 2 0.50 ... 0.50 0.50 0.25 0.50 1 1 1 1 1 1
25 2 79 9 5 5 1 3 1 2 0.75 ... 0.00 0.50 0.00 0.25 1 2 1 2 1 1
26 2 23 9 1 3 1 4 1 2 0.75 ... 0.75 1.00 1.00 1.00 1 2 1 1 2 1
27 2 32 9 2 3 1 3 1 1 0.75 ... 0.50 0.00 0.00 0.75 1 1 1 1 1 1
28 2 23 9 1 3 1 4 1 2 0.75 ... 0.50 0.00 0.75 0.50 1 1 1 1 1 1
29 1 45 9 2 4 1 3 1 1 0.75 ... 0.75 0.25 0.25 0.50 1 1 1 1 1 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
469 1 18 9 1 3 8 1 1 1 0.75 ... 0.50 0.50 0.00 0.50 1 1 1 1 1 1
470 1 22 9 1 4 8 1 1 2 0.75 ... 0.75 0.75 0.50 0.50 1 1 1 1 1 1
471 1 56 9 2 5 1 1 1 1 1.00 ... 0.25 1.00 0.25 1.00 1 2 1 1 1 1
472 1 45 9 4 4 1 4 1 2 1.00 ... 0.00 0.75 0.25 0.75 1 1 1 1 1 1
473 1 23 9 1 4 2 4 2 1 0.25 ... 0.00 0.25 0.25 0.50 2 1 1 1 1 1
474 2 22 9 1 4 2 3 2 2 0.75 ... 0.25 0.25 0.75 0.50 1 1 1 1 1 1
475 2 21 9 1 4 1 3 1 2 0.25 ... 0.50 0.50 0.00 0.25 2 1 1 1 1 1
476 2 18 9 1 3 8 1 2 1 0.50 ... 0.75 0.50 0.50 0.50 2 1 1 1 1 1
477 2 45 9 2 4 1 3 1 1 0.50 ... 0.00 0.75 0.00 1.00 1 1 1 1 1 1
478 2 44 9 2 4 1 3 1 1 0.25 ... 0.25 0.25 0.50 0.25 1 1 1 1 1 1
479 2 19 9 1 3 8 1 1 2 0.00 ... 0.50 0.50 0.75 0.50 1 1 1 1 1 1
480 2 22 9 1 4 8 1 3 2 0.75 ... 0.25 0.75 0.50 0.75 1 1 1 1 1 1
481 2 21 9 1 4 7 1 1 1 0.25 ... 0.75 1.00 0.50 0.25 2 1 1 1 1 1
482 2 26 9 1 4 8 1 1 2 0.25 ... 0.75 0.75 0.50 0.50 1 1 1 1 1 1
483 2 28 9 2 4 1 3 1 1 0.75 ... 0.00 1.00 0.25 0.75 1 1 1 1 1 1
484 2 30 9 2 4 1 2 1 1 0.50 ... 0.00 0.50 0.25 0.50 1 1 1 1 1 1
485 2 32 9 3 4 1 2 1 1 0.75 ... 0.25 0.50 0.25 0.25 1 1 1 1 1 1
486 2 35 9 3 4 8 1 1 1 0.75 ... 0.50 0.50 0.00 0.50 1 1 1 1 1 1
487 2 37 9 2 4 7 1 1 1 0.25 ... 0.50 0.75 0.00 0.50 1 1 1 1 1 1
488 2 18 9 1 3 8 1 2 2 0.50 ... 0.75 0.50 0.00 0.50 1 1 1 1 1 1
489 1 21 9 1 4 1 2 1 2 1.00 ... 0.00 0.50 0.75 0.75 1 1 1 1 1 1
490 1 35 14 2 4 1 2 1 1 1.00 ... 0.25 0.50 0.50 0.25 2 1 1 1 1 1
491 2 27 15 4 4 8 1 1 2 0.50 ... 0.00 1.00 0.00 0.50 2 2 1 1 2 2
492 2 22 15 1 3 8 1 2 2 0.75 ... 1.00 0.25 0.25 0.75 1 1 1 1 1 1
493 1 21 9 2 3 8 1 1 1 1.00 ... 0.25 0.50 0.00 0.25 1 2 1 1 1 1
494 2 24 9 3 4 1 3 1 1 0.75 ... 0.50 0.50 0.25 0.50 1 1 1 1 1 1
495 2 25 17 1 4 2 4 1 2 0.75 ... 0.25 0.25 0.25 0.75 1 1 1 1 1 1
496 2 23 12 2 3 3 3 2 1 0.50 ... 0.25 0.50 0.50 0.50 1 1 1 1 1 1
497 1 27 9 1 4 1 2 1 2 1.00 ... 0.50 1.00 0.00 1.00 2 1 2 2 1 1
498 1 33 9 1 4 9 3 1 2 0.00 ... 0.25 0.75 0.00 0.75 1 1 1 1 1 1

490 rows × 60 columns


In [24]:
n_data.info()


<class 'pandas.core.frame.DataFrame'>
Int64Index: 490 entries, 0 to 498
Data columns (total 60 columns):
Sexo                     490 non-null int64
Edad                     483 non-null float64
Lugar_Origen             481 non-null object
Estado_civil             486 non-null float64
Escolaridad              309 non-null float64
Orientacion_Religiosa    490 non-null int64
Practicante              484 non-null float64
Orientacion_Sexual       483 non-null float64
Pareja                   490 non-null int64
Emocion1                 490 non-null float64
Emocion2                 490 non-null float64
Emocion3                 490 non-null float64
Emocion4                 490 non-null float64
Emocion8                 490 non-null float64
Emocion9                 490 non-null float64
Emocion14                490 non-null float64
Emocion15                490 non-null float64
Emocion17                490 non-null float64
Emocion21                490 non-null float64
Emocion26                490 non-null float64
Emocion28                490 non-null float64
Emocion34                490 non-null float64
Emocion36                490 non-null float64
Cognicion6               490 non-null float64
Cognicion7               490 non-null float64
Cognicion9               490 non-null float64
Cognicion10              490 non-null float64
Cognicion11              490 non-null float64
Cognicion15              490 non-null float64
Cognicion21              490 non-null float64
Cognicion30              490 non-null float64
Cognicion41              490 non-null float64
Cognicion47              490 non-null float64
Cognicion50              490 non-null float64
Cognicion54              490 non-null float64
Cognicion58              490 non-null float64
Cognicion65              490 non-null float64
Cognicion74              490 non-null float64
Cognicion75              490 non-null float64
Cognicion78              490 non-null float64
Conducta1                490 non-null float64
Conducta2                490 non-null float64
Conducta6                490 non-null float64
Conducta13               490 non-null float64
Conducta19               490 non-null float64
Conducta21               490 non-null float64
Conducta23               490 non-null float64
Conducta25               490 non-null float64
Conducta31               490 non-null float64
Conducta32               490 non-null float64
Conducta36               490 non-null float64
Conducta41               490 non-null float64
Conducta46               490 non-null float64
Conducta52               490 non-null float64
Creencia2                490 non-null int64
Creencia12               490 non-null int64
Creencia27               490 non-null int64
Creencia37               490 non-null int64
Creencia39               490 non-null int64
Creencia49               490 non-null int64
dtypes: float64(50), int64(9), object(1)
memory usage: 233.5+ KB

In [25]:
cols_adultos = ['Emocion4', 'Emocion9', 'Emocion15', 'Emocion34', 'Emocion36', 'Cognicion6',
         'Cognicion10', 'Cognicion41', 'Cognicion50', 'Cognicion58', 'Conducta25', 'Conducta32',
         'Conducta41', 'Conducta46']
cols_jovenes = ['Emocion1', 'Emocion8', 'Emocion28', 'Cognicion7', 'Cognicion9', 'Cognicion11',
               'Cognicion15', 'Cognicion30', 'Cognicion47', 'Cognicion74', 'Cognicion75', 'Conducta2',
               'Conducta6', 'Conducta13']
cols_corr = ['Emocion2', 'Cognicion21', 'Cognicion65', 'Conducta23', 'Emocion21', 'Conducta52']
cols_carac = ['Sexo', 'Edad', 'Lugar_Origen', 'Estado_civil',
                   'Escolaridad', 'Orientacion_Religiosa', 'Practicante', 'Orientacion_Sexual',
                   'Pareja']

Se limpian los datos, se seleccionan las columnas que dan informacion acerca de prejuicios contra jóvenes y contra adultos. Se normalizan y escalan los datos de una escala de 1 a 5 a una escala de 0 a 1 para simplificar los cálculos y poder obtener un score para cada encuestado


In [26]:
n_data[cols_jovenes].describe()


Out[26]:
Emocion1 Emocion8 Emocion28 Cognicion7 Cognicion9 Cognicion11 Cognicion15 Cognicion30 Cognicion47 Cognicion74 Cognicion75 Conducta2 Conducta6 Conducta13
count 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000
mean 0.567347 0.455102 0.535714 0.570408 0.471939 0.549490 0.314796 0.297959 0.269388 0.314286 0.505102 0.557653 0.500000 0.569388
std 0.267162 0.326527 0.270858 0.296782 0.283047 0.291275 0.280156 0.289552 0.291112 0.267439 0.311216 0.277602 0.301665 0.291813
min 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
25% 0.500000 0.250000 0.312500 0.250000 0.250000 0.250000 0.000000 0.000000 0.000000 0.000000 0.250000 0.500000 0.250000 0.500000
50% 0.500000 0.500000 0.500000 0.500000 0.500000 0.500000 0.250000 0.250000 0.250000 0.250000 0.500000 0.500000 0.500000 0.500000
75% 0.750000 0.750000 0.750000 0.750000 0.750000 0.750000 0.500000 0.500000 0.500000 0.500000 0.750000 0.750000 0.750000 0.750000
max 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000

In [27]:
n_data[cols_adultos].describe()


Out[27]:
Emocion4 Emocion9 Emocion15 Emocion34 Emocion36 Cognicion6 Cognicion10 Cognicion41 Cognicion50 Cognicion58 Conducta25 Conducta32 Conducta41 Conducta46
count 490.000000 490.000000 490.00000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000 490.000000
mean 0.537755 0.441327 0.44898 0.465306 0.409184 0.257653 0.379082 0.261224 0.292347 0.244388 0.515816 0.570408 0.516327 0.463265
std 0.251484 0.364239 0.39091 0.393675 0.391849 0.276125 0.266666 0.261497 0.319553 0.264834 0.286238 0.259565 0.286879 0.320846
min 0.000000 0.000000 0.00000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
25% 0.250000 0.000000 0.00000 0.000000 0.000000 0.000000 0.250000 0.000000 0.000000 0.000000 0.250000 0.500000 0.250000 0.250000
50% 0.500000 0.500000 0.50000 0.500000 0.250000 0.250000 0.500000 0.250000 0.250000 0.250000 0.500000 0.500000 0.500000 0.500000
75% 0.750000 0.750000 0.75000 0.937500 0.750000 0.500000 0.500000 0.500000 0.500000 0.500000 0.750000 0.750000 0.750000 0.750000
max 1.000000 1.000000 1.00000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000

In [28]:
n_data['score_vs_adultos'] = n_data[cols_adultos].sum(axis=1)/14
n_data['score_vs_jovenes'] = n_data[cols_jovenes].sum(axis=1)/14

Se calcula el score de prejuicio contra adultos y contra jóvenes de cada encuestado. El score va de un rango de 0 a 1.


In [29]:
n_data[['score_vs_adultos', 'score_vs_jovenes']]


Out[29]:
score_vs_adultos score_vs_jovenes
0 0.357143 0.553571
1 0.446429 0.750000
2 0.428571 0.642857
3 0.410714 0.553571
4 0.410714 0.553571
5 0.553571 0.571429
6 0.482143 0.607143
7 0.375000 0.517857
8 0.375000 0.446429
9 0.535714 0.589286
10 0.392857 0.535714
11 0.339286 0.678571
12 0.214286 0.410714
13 0.178571 0.357143
14 0.285714 0.821429
15 0.303571 0.410714
16 0.160714 0.375000
17 0.285714 0.446429
18 0.125000 0.303571
19 0.232143 0.482143
20 0.196429 0.285714
21 0.392857 0.607143
22 0.232143 0.375000
23 0.339286 0.500000
24 0.196429 0.339286
25 0.428571 0.750000
26 0.535714 0.750000
27 0.339286 0.553571
28 0.375000 0.571429
29 0.607143 0.571429
... ... ...
469 0.482143 0.553571
470 0.517857 0.642857
471 0.589286 0.589286
472 0.553571 0.625000
473 0.410714 0.446429
474 0.410714 0.517857
475 0.535714 0.500000
476 0.517857 0.410714
477 0.464286 0.571429
478 0.392857 0.589286
479 0.535714 0.446429
480 0.500000 0.535714
481 0.410714 0.464286
482 0.482143 0.553571
483 0.535714 0.464286
484 0.464286 0.535714
485 0.446429 0.571429
486 0.357143 0.464286
487 0.500000 0.428571
488 0.446429 0.517857
489 0.517857 0.500000
490 0.375000 0.535714
491 0.553571 0.660714
492 0.214286 0.232143
493 0.303571 0.446429
494 0.375000 0.357143
495 0.321429 0.553571
496 0.339286 0.321429
497 0.910714 0.607143
498 0.303571 0.464286

490 rows × 2 columns


In [30]:
n_data[n_data['score_vs_adultos'] >= 0.6]


Out[30]:
Sexo Edad Lugar_Origen Estado_civil Escolaridad Orientacion_Religiosa Practicante Orientacion_Sexual Pareja Emocion1 ... Conducta46 Conducta52 Creencia2 Creencia12 Creencia27 Creencia37 Creencia39 Creencia49 score_vs_adultos score_vs_jovenes
29 1 45 9 2 4 1 3 1 1 0.75 ... 0.25 0.50 1 1 1 1 1 1 0.607143 0.571429
53 1 35 15 2 NaN 1 2 1 1 0.50 ... 1.00 0.00 1 2 1 1 2 1 0.607143 0.607143
67 1 21 15 1 4 1 2 1 2 1.00 ... 0.25 0.75 1 2 1 1 1 1 0.625000 0.553571
70 1 20 9 1 4 1 1 1 2 0.50 ... 0.50 0.50 1 1 1 1 1 1 0.625000 0.571429
73 1 20 24 1 NaN 7 1 1 1 0.75 ... 0.00 0.75 2 1 2 2 2 2 0.642857 0.607143
172 2 26 15 1 NaN 1 2 1 1 0.25 ... 1.00 0.25 1 1 1 1 1 1 0.625000 0.500000
178 1 21 15 3 NaN 1 1 1 1 0.50 ... 0.75 0.50 2 1 1 1 1 2 0.625000 0.410714
183 2 39 15 1 NaN 8 1 1 2 0.50 ... 0.75 0.25 1 1 1 1 1 1 0.625000 0.446429
185 1 NaN NaN 2 NaN 1 2 NaN 1 0.75 ... 0.75 0.75 1 1 1 1 1 1 0.607143 0.482143
199 1 19 20 1 NaN 1 2 2 2 0.50 ... 1.00 0.50 2 1 1 1 1 1 0.642857 0.535714
251 2 26 15 1 4 1 2 1 1 0.25 ... 1.00 0.25 1 1 1 1 1 1 0.625000 0.500000
257 1 21 15 3 2 1 1 1 1 0.50 ... 0.75 0.50 2 1 1 1 1 2 0.625000 0.410714
262 2 39 15 1 3 8 1 1 2 0.50 ... 0.75 0.25 1 1 1 1 1 1 0.625000 0.446429
264 1 NaN NaN 2 4 1 2 NaN 1 0.75 ... 0.75 0.75 1 1 1 1 1 1 0.607143 0.482143
278 1 19 20 1 4 1 2 2 2 0.50 ... 1.00 0.50 2 1 1 1 1 1 0.642857 0.535714
316 2 19 9 1 NaN 1 3 1 2 0.50 ... 1.00 0.75 1 1 1 1 1 1 0.625000 0.517857
320 2 20 9 1 NaN 2 1 1 2 0.25 ... 1.00 0.50 1 2 1 1 1 1 0.607143 0.464286
349 2 21 9 1 NaN 7 1 1 1 0.50 ... 0.50 0.50 1 1 1 1 1 1 0.607143 0.410714
365 1 56 9 2 NaN 1 2 1 1 0.50 ... 0.50 0.50 1 1 1 1 1 1 0.660714 0.571429
366 2 21 9 1 NaN 1 3 1 2 0.75 ... 0.50 0.50 1 1 1 1 1 1 0.642857 0.500000
377 1 62 9 5 5 1 2 1 2 0.25 ... 1.00 0.50 1 1 1 1 1 1 0.607143 0.446429
395 2 21 9 1 4 1 2 1 1 0.25 ... 1.00 0.00 2 1 1 1 1 1 0.607143 0.464286
497 1 27 9 1 4 1 2 1 2 1.00 ... 0.00 1.00 2 1 2 2 1 1 0.910714 0.607143

23 rows × 62 columns


In [31]:
n_data[n_data['score_vs_jovenes'] >= 0.6]


Out[31]:
Sexo Edad Lugar_Origen Estado_civil Escolaridad Orientacion_Religiosa Practicante Orientacion_Sexual Pareja Emocion1 ... Conducta46 Conducta52 Creencia2 Creencia12 Creencia27 Creencia37 Creencia39 Creencia49 score_vs_adultos score_vs_jovenes
1 1 50 9 2 3 1 2 1 1 1.00 ... 0.25 1.00 1 2 1 1 1 2 0.446429 0.750000
2 2 19 9 1 4 2 3 1 0 0.75 ... 0.75 1.00 1 1 1 1 1 1 0.428571 0.642857
6 1 20 9 1 3 1 3 1 2 1.00 ... 0.25 0.75 1 2 1 1 1 2 0.482143 0.607143
11 2 19 9 1 4 1 2 1 1 1.00 ... 0.50 0.75 2 2 1 1 1 1 0.339286 0.678571
14 2 43 9 2 3 1 4 1 1 0.75 ... 0.75 0.75 1 2 1 1 2 1 0.285714 0.821429
21 1 22 1 1 4 1 4 1 2 0.75 ... 0.50 0.50 1 1 1 1 1 1 0.392857 0.607143
25 2 79 9 5 5 1 3 1 2 0.75 ... 0.00 0.25 1 2 1 2 1 1 0.428571 0.750000
26 2 23 9 1 3 1 4 1 2 0.75 ... 1.00 1.00 1 2 1 1 2 1 0.535714 0.750000
32 2 29 16 1 NaN 8 1 3 2 1.00 ... 0.75 0.75 2 1 1 1 1 1 0.589286 0.660714
52 1 23 15 1 4 1 1 1 2 0.75 ... 0.25 0.75 1 2 1 1 2 1 0.517857 0.660714
53 1 35 15 2 NaN 1 2 1 1 0.50 ... 1.00 0.00 1 2 1 1 2 1 0.607143 0.607143
73 1 20 24 1 NaN 7 1 1 1 0.75 ... 0.00 0.75 2 1 2 2 2 2 0.642857 0.607143
79 2 21 15 1 NaN 1 2 1 1 1.00 ... 0.50 1.00 1 1 1 1 1 1 0.339286 0.607143
80 1 37 9 2 5 1 2 1 1 0.75 ... 0.75 0.75 1 2 1 1 1 2 0.392857 0.660714
104 1 21 9 1 3 1 2 1 2 0.75 ... 0.50 0.75 2 1 1 1 1 1 0.464286 0.642857
106 2 21 15 1 3 1 2 1 1 0.75 ... 0.25 1.00 1 1 1 1 1 1 0.303571 0.660714
108 1 18 9 1 3 1 1 1 2 0.50 ... 0.75 1.00 2 1 2 1 1 1 0.500000 0.625000
154 2 25 9 2 3 1 2 1 1 1.00 ... 0.50 0.75 2 1 1 1 1 1 0.375000 0.660714
156 2 62 9 1 2 1 4 1 1 1.00 ... 0.25 1.00 1 1 1 1 1 1 0.303571 0.678571
158 1 18 9 1 3 1 2 1 1 0.50 ... 0.75 1.00 2 1 2 1 1 1 0.535714 0.607143
184 1 23 15 1 NaN 1 2 NaN 2 0.25 ... 1.00 0.25 1 1 1 1 1 1 0.589286 0.607143
187 2 20 9 1 NaN 1 1 1 2 0.50 ... 1.00 0.50 2 1 1 1 1 1 0.553571 0.607143
198 2 20 9 1 NaN 1 3 1 2 0.25 ... 0.25 0.75 2 1 1 1 2 1 0.375000 0.607143
216 2 23 9 1 4 1 3 2 1 0.75 ... 0.25 0.75 1 2 1 1 1 1 0.303571 0.607143
225 1 47 9 2 4 1 3 1 1 0.50 ... 0.50 0.50 2 2 1 1 1 1 0.446429 0.625000
236 1 26 20 1 NaN 1 3 1 2 0.75 ... 0.50 0.00 1 1 1 1 1 1 0.303571 0.607143
263 1 23 15 1 3 1 2 NaN 2 0.25 ... 1.00 0.25 1 1 1 1 1 1 0.589286 0.607143
266 2 20 9 1 4 1 1 1 2 0.50 ... 1.00 0.50 2 1 1 1 1 1 0.553571 0.607143
277 2 20 9 1 4 1 3 1 2 0.25 ... 0.25 0.75 2 1 1 1 2 1 0.375000 0.607143
290 1 22 9 1 4 8 1 1 2 0.75 ... 0.50 0.50 1 1 1 1 1 1 0.517857 0.642857
292 1 45 9 4 4 1 4 1 2 1.00 ... 0.25 0.75 1 1 1 1 1 1 0.553571 0.625000
332 1 52 9 2 NaN 1 2 1 1 1.00 ... 0.25 1.00 1 1 1 1 1 2 0.446429 0.750000
385 2 21 9 1 4 1 2 1 2 0.50 ... 1.00 1.00 1 2 1 2 1 2 0.464286 0.660714
397 1 19 9 2 3 1 3 1 2 0.75 ... 0.75 1.00 1 2 1 1 1 1 0.517857 0.642857
398 1 20 9 1 3 2 4 2 1 1.00 ... 0.50 1.00 1 2 1 2 1 2 0.428571 0.696429
440 1 22 9 1 4 1 1 1 2 0.75 ... 0.50 0.50 1 1 1 1 1 1 0.517857 0.642857
442 1 44 9 4 4 1 4 1 2 1.00 ... 0.25 0.75 1 1 1 1 1 1 0.553571 0.625000
470 1 22 9 1 4 8 1 1 2 0.75 ... 0.50 0.50 1 1 1 1 1 1 0.517857 0.642857
472 1 45 9 4 4 1 4 1 2 1.00 ... 0.25 0.75 1 1 1 1 1 1 0.553571 0.625000
491 2 27 15 4 4 8 1 1 2 0.50 ... 0.00 0.50 2 2 1 1 2 2 0.553571 0.660714
497 1 27 9 1 4 1 2 1 2 1.00 ... 0.00 1.00 2 1 2 2 1 1 0.910714 0.607143

41 rows × 62 columns

Se puede fijar un threshold para contestar la pregunta, sin embargo es más práctico clasificarlos sin un valor de corte (threshold), y sólo usar si un score es mayor que otro para contestar la pregunta.


In [35]:
jovenes = n_data[n_data['score_vs_jovenes'] > n_data['score_vs_adultos']]
len(jovenes)


Out[35]:
294

In [36]:
adultos = n_data[n_data['score_vs_jovenes'] < n_data['score_vs_adultos']]
len(adultos)


Out[36]:
169

In [37]:
iguales = n_data[n_data['score_vs_jovenes'] == n_data['score_vs_adultos']]
len(iguales)


Out[37]:
27

In [38]:
sns.countplot(x=n_data.score_vs_adultos > n_data.score_vs_jovenes)


Out[38]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fae2239ed90>

azul: prejuiciosos vs jovenes

verde: prejuiciosos vs adultos

Número de encuestados prejuiciosos contra jóvenes: 295

Número de encuestados prejuiciosos contra adultos: 169

Número de encuestados con mismo nivel de prejuicio contra ambos: 27

El último número, son los encuestados que no pudieron ser clasificados dentro de ninguna

clase


In [39]:
graph = sns.jointplot(x=n_data.score_vs_jovenes, y=n_data.score_vs_adultos, color='g')

graph.x = n_data.score_vs_jovenes
graph.y = n_data.score_vs_adultos
graph.plot_joint(plt.scatter, marker='x', c='b', s=50)


Out[39]:
<seaborn.axisgrid.JointGrid at 0x7fae1e60f190>

In [40]:
corr_adultos = n_data[cols_carac + ['score_vs_adultos', 'score_vs_jovenes']].corr()

In [41]:
corr_adultos


Out[41]:
Sexo Edad Estado_civil Escolaridad Orientacion_Religiosa Practicante Orientacion_Sexual Pareja score_vs_adultos score_vs_jovenes
Sexo 1.000000 -0.064313 -0.032094 0.033028 0.071631 0.026682 -0.028757 -0.049749 -0.028286 -0.123083
Edad -0.064313 1.000000 0.587234 0.177278 -0.121241 0.078670 -0.175641 -0.216955 -0.084358 0.164013
Estado_civil -0.032094 0.587234 1.000000 0.135745 -0.041611 0.118514 -0.133019 -0.087465 -0.060408 0.083809
Escolaridad 0.033028 0.177278 0.135745 1.000000 -0.025169 0.095910 -0.079197 0.032161 -0.093597 -0.095982
Orientacion_Religiosa 0.071631 -0.121241 -0.041611 -0.025169 1.000000 -0.277538 0.050756 -0.005986 -0.115389 -0.128699
Practicante 0.026682 0.078670 0.118514 0.095910 -0.277538 1.000000 -0.127457 0.129173 -0.016621 0.020348
Orientacion_Sexual -0.028757 -0.175641 -0.133019 -0.079197 0.050756 -0.127457 1.000000 0.086724 -0.065984 -0.023642
Pareja -0.049749 -0.216955 -0.087465 0.032161 -0.005986 0.129173 0.086724 1.000000 0.034746 0.018461
score_vs_adultos -0.028286 -0.084358 -0.060408 -0.093597 -0.115389 -0.016621 -0.065984 0.034746 1.000000 0.374251
score_vs_jovenes -0.123083 0.164013 0.083809 -0.095982 -0.128699 0.020348 -0.023642 0.018461 0.374251 1.000000

In [42]:
sns.heatmap(corr_adultos)


Out[42]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fae2455b1d0>

El heatmap muestra la correlación entre las características de los encuestados y los scores,

más rojo significa mayor correlación, más azul significa mayor correlación negativa.


In [ ]: